package com.easy.service.Impl;

import com.easy.bean.Inventory;
import com.easy.mapper.InventoryMapper;
import com.easy.service.InventoryService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true) // 默认只读
public class InventoryServiceImpl implements InventoryService {
    @Autowired
    InventoryMapper inventoryMapper;

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public Inventory add(Inventory inventory) {
        inventoryMapper.add(inventory);
        Inventory result = inventoryMapper.one(inventory.getStock_id());
        return result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public int del(Integer id) {
        return inventoryMapper.del(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public Inventory edit(Inventory inventory) {
        inventoryMapper.edit(inventory);
        Inventory result = inventoryMapper.one(inventory.getStock_id());
        return result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public List<Inventory> all(Inventory inventory) {
        return inventoryMapper.all(inventory);
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public Inventory one(Integer id) {
        return inventoryMapper.one(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class) // 写操作
    public void page(Page page, Inventory inventory) {
        int count=inventoryMapper.pageCount(inventory);
        Object data=inventoryMapper.page(page,inventory);
        page.setCount(count);
        page.setData(data);
    }
}
